// CollectionController.java
package com.sun.huazhi.aitaskservice.controller;

import com.sun.huazhi.aitaskservice.DTO.response.*;
import com.sun.huazhi.aitaskservice.common.config.PythonApiProperties;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/api/collection")
@Tag(name = "图像合集管理", description = "提供图像合集和元数据管理功能")
public class CollectionController {

    @Autowired
    @Qualifier("pythonApiProperties")
    private PythonApiProperties apiProps;

    @Autowired
    private WebClient webClient;

    @GetMapping("/")
    @Operation(summary = "列出所有图像合集", description = "获取系统中所有可用的图像合集列表")
    public Mono<ResponseEntity<CollectionListResponse>> listCollections() {
        return webClient.get()
                .uri(apiProps.getUrl() + "/list-collections")
                .retrieve()
                .bodyToMono(CollectionListResponse.class)
                .map(ResponseEntity::ok);
    }

    @GetMapping("/{collectionId}")
    @Operation(summary = "获取合集详情", description = "根据合集ID获取特定合集的详细信息")
    public Mono<ResponseEntity<CollectionDetailResponse>> getCollection(
            @PathVariable String collectionId) {

        return webClient.get()
                .uri(apiProps.getUrl() + "/collection/" + collectionId)
                .retrieve()
                .bodyToMono(CollectionDetailResponse.class)
                .map(ResponseEntity::ok);
    }

    @GetMapping("/image/{imageId}/metadata")
    @Operation(summary = "获取图像元数据", description = "根据图像ID获取特定图像的元数据信息")
    public Mono<ResponseEntity<ImageMetadataResponse>> getImageMetadata(
            @PathVariable String imageId) {

        return webClient.get()
                .uri(apiProps.getUrl() + "/image-metadata/" + imageId)
                .retrieve()
                .bodyToMono(ImageMetadataResponse.class)
                .map(ResponseEntity::ok);
    }
}